<!--Create: LT4-->
<!--Time:   2020年6月16日18:35:21-->
<!--Description:    显示购物车列表 -->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>选择地址</title>
    <link rel="stylesheet" href="../../../static/css/bootstrap.min.css"
          th:href="@{../../../static/css/bootstrap.min.css}">

</head>
<body>
<header>
    <nav class="navbar navbar-light bg-light navbar-expand">
        <a href="/" class="navbar-brand">Shop</a>
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a href="/" class="nav-link active">首页</a>
                </li>
                <form class="form-inline">
                    <input id="searchText" type="text" placeholder="Search" class="form-control"/>
                </form>
                <button id="search" class="btn btn-primary">搜索</button>
            </ul>
        </div>
        <div th:if="${#strings.isEmpty(session.user)}">
            <div class="btn-group">
                <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">登录</button>
                <div class="dropdown-menu dropdown-menu-right p-2 text-muted" style="width: 300px">
                    <form action="/userLogin" data-stopPropagation="true" method="post">
                        <div class="form-group">
                            <input type="hidden" id="path" name="path" value="/">
                        </div>
                        <div class="form-group" data-stop>
                            <label>用户名:</label>
                            <input id="username" name="username" type="text" class="form-control"
                                   placeholder="username">
                            <div id="noUsername" class="alert alert-danger alert-dismissible fade show"
                                 style="display:none">
                                <strong>用户名不能为空</strong>
                                <button id="noUserBtn" type="button" class="close">&times;</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>密码:</label>
                            <input id="password" name="password" type="password" class="form-control"
                                   placeholder="password">
                            <div id="noPassword" class="alert alert-danger alert-dismissible fade show"
                                 style="display:none">
                                <strong>请输入密码</strong>
                                <button id="noPwdBtn" type="button" class="close">&times;</button>
                            </div>
                        </div>
                        <div class="form-group" style="margin-top: 2px">
                            <button id="loginSubmit" type="submit" class="btn btn-primary" style="width: 100%;">登录
                            </button>
                            <span id="err" th:if="${not #strings.isEmpty(loginMsg)}">
                                    <div class="alert alert-danger alert-dismissible fade show">
                                        <strong th:text="${loginMsg}"></strong>
                                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                                    </div>
                                </span>
                        </div>
                        <div class="text-center">
                            <a href="/enroll">>前往注册</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="user" th:if="${session.user}">
            <img th:onclick="'javascript:locate(\''+'/user/'+${session.user.id}+'\')'"
                 style="height: 45px;width: 45px;margin-right: 20px"
                 class="rounded-circle dropdown-toggle" data-toggle="dropdown"
                 th:src="${session.user.iconURL!=null}?${session.iconPathPattern}+${session.user.iconURL}:@{/static/img/default.png}">
            <ul class="dropdown-menu dropdown-menu-right p-2 text-muted" role="menu" style="width: 100px">
                <a class="dropdown-item" href="/show/order/list">我的订单</a>
                <a class="dropdown-item" href="/show/order/cart">我的购物车</a>
                <a th:if="${session.user.state==1}" class="dropdown-item" href="/dashboard">管理</a>
            </ul>
            <span style="padding-right: 40px" th:text="${session.user.getUsername()}"></span>
        </div>

    </nav>

</header>
<br>

<main role="main">
    <main role="main">
        <div class="container" style="margin-top: 200px">
            <div class="col-md-6 offset-md-3">
                <div class="card">
                    <div class="card-body">
                        <form action="/pay" method="post">
                            <fieldset class="form-group">
                                <div class="row">
                                    <legend class="col-form-label col-md-4">地址选择</legend>
                                    <div class="col-md-10">
                                        <div class="form-check" th:each="item : ${list}">
                                            <input class="form-check-input" type="radio" name="addressId"
                                                   id="gridRadios1" th:value="${item.id}">
                                            <label class="form-check-label" for="gridRadios1" th:text="${item.address}">
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <div class="form-group row">
                                <input name="oid" type="hidden" th:value="${oid}">
                            </div>
                            <div class="form-group row">
                                <div class="col-md-5">
                                    <button type="submit" class="btn btn-primary">确定</button>
                                </div>
                                <div class="col-md-5">
                                    <a id="pay" class="btn btn-primary" th:href="@{'/show/address/add/'+${oid}}">添加新地址</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </main>

</main>


</body>

<script type="text/javascript" src="../../../static/js/jquery-3.3.1.js"
        th:src="@{../../../static/js/jquery-3.3.1.js}"></script>
<script type="text/javascript" src="../../../static/js/popper.min.js"
        th:src="@{../../../static/js/popper.min.js}"></script>
<script type="text/javascript" src="../../../static/js/bootstrap.min.js"
        th:src="@{../../../static/js/bootstrap.min.js}"></script>

<script type="text/javascript">
    window.onload = function () {
        //alert(1);
    }
    $(function () {
        $(".dropdown-toggle").on("mouseover", function () {
            $(this).dropdown('toggle');
        })
    })

    function pay(id) {
        $.ajax({
            type: 'put',
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            url: 'http://localhost:8000/show/order/state',
            data: JSON.stringify({
                "id": id,
                "state": "1",
            }),
            success: function (data) {
                console.log(data["msg"]);
                window.location.href = "http://localhost:8000" + data["locate"];
            },
            error: function (data) {
                console.log(data["msg"]);
            }
        });

    }

    function locate(string) {
        window.open(string);
    }
</script>

</html>